package com.blog.controller.adminannouncement;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blog.controller.base.BaseServlet;
import com.blog.entity.NoticeEntity;
import com.blog.service.adminannouncement.AdminNoticeService;

@WebServlet("/adminAjaxNotice")
public class AdminAjaxNoticeServlet extends BaseServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		// 根据时间查询所有公告
		AdminNoticeService service = new AdminNoticeService();
		// 获得日期
		String onedate = req.getParameter("date1");
		String twodate = req.getParameter("date2");
		if ((onedate != null && !onedate.isEmpty()) && (twodate != null && !twodate.isEmpty())) {
			List<NoticeEntity> queryNoticeByTime = service.queryNoticeByTime(onedate, twodate, 0);
			String str = null;
			for (NoticeEntity noticeEntity : queryNoticeByTime) {
				str = "<div class=\"content_list\">\r\n" + "						<ul>\r\n"
						+ "							<li>\r\n"
						+ "								<div class=\"list_top\">\r\n"
						+ "									<div class=\"list_top_div\" style=\"padding-left: 20px\">标题："
						+ noticeEntity.getNotice_title() + "</div>\r\n"
						+ "									<div class=\"list_top_div\">发表时间："
						+ noticeEntity.getNotice_time() + "</div>\r\n"
						+ "									<div class=\"list_top_div\">发表人："
						+ noticeEntity.getNotice_personid() + "</div>\r\n"
						+ "									<div style=\"clear: both\"></div>\r\n"
						+ "								</div>\r\n"
						+ "								<div class=\"list_content\">正文："
						+ noticeEntity.getNotice_content() + "</div>\r\n" + "							</li>\r\n"
						+ "						</ul>\r\n" + "					</div>";

				resp.getWriter().println(str);
			}
		}

		String title = req.getParameter("title");
		if ((title != null && !title.isEmpty())) {
			List<NoticeEntity> queryNoticeByTitle = service.queryNoticeByInput(title, 0);
			String titleStr = null;
			for (NoticeEntity noticeEntity : queryNoticeByTitle) {
				titleStr = "<div class=\"content_list\">\r\n" + "						<ul>\r\n"
						+ "							<li>\r\n"
						+ "								<div class=\"list_top\">\r\n"
						+ "									<div class=\"list_top_div\" style=\"padding-left: 20px\">标题："
						+ noticeEntity.getNotice_title() + "</div>\r\n"
						+ "									<div class=\"list_top_div\">发表时间："
						+ noticeEntity.getNotice_time() + "</div>\r\n"
						+ "									<div class=\"list_top_div\">发表人："
						+ noticeEntity.getNotice_personid() + "</div>\r\n"
						+ "									<div style=\"clear: both\"></div>\r\n"
						+ "								</div>\r\n"
						+ "								<div class=\"list_content\">正文："
						+ noticeEntity.getNotice_content() + "</div>\r\n" + "							</li>\r\n"
						+ "						</ul>\r\n" + "					</div>";

				resp.getWriter().println(titleStr);
			}
		}

		// 点击状态
		String status = req.getParameter("status");
		int flag = 0;
		if (status != null && !status.isEmpty()) {
			flag = Integer.parseInt(status);
			List<NoticeEntity> queryNoticeByTitle = service.queryAllNoticeByTypes(flag);
			String types = null;
			for (NoticeEntity noticeEntity : queryNoticeByTitle) {
				types = "<div class=\"content_list\">\r\n" + "						<ul>\r\n"
						+ "							<li>\r\n"
						+ "								<div class=\"list_top\">\r\n"
						+ "									<div class=\"list_top_div\" style=\"padding-left: 20px\">标题："
						+ noticeEntity.getNotice_title() + "</div>\r\n"
						+ "									<div class=\"list_top_div\">发表时间："
						+ noticeEntity.getNotice_time() + "</div>\r\n"
						+ "									<div class=\"list_top_div\">发表人："
						+ noticeEntity.getNotice_personid() + "</div>\r\n"
						+ "									<div style=\"clear: both\"></div>\r\n"
						+ "								</div>\r\n"
						+ "								<div class=\"list_content\">正文："
						+ noticeEntity.getNotice_content() + "</div>\r\n" + "							</li>\r\n"
						+ "						</ul>\r\n" + "					</div>";

				resp.getWriter().println(types);
			}
		}

	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

	}
}
